<include file="System:leftmenu" />
<div class="content-right fl">

    <h1 class="content-right-title">SEO设置</h1>

    <form action="" id="form" method="POST"  onsubmit="return false;">

        <div class="formitems">
        </div>
        <div class="formitems">
            <label class="fi-name"><span class="colorRed">*</span>打印机名称：</label>
            <div class="form-controls">
                <input type="text" class="input xxlarge" name="PRINTER" value="<?php echo C("PRINTER");?>"><a style="text-decoration:underline" href="javascript:doGetPrinters();">获取打印机信息</a>

                <span class="fi-help-text">打印机名称</span>
            </div>
        </div>
        <label class="fi-name"><span class="colorRed"></span>打印机信息:</label>
        <div id="print_info">

        </div>
        <div class="mgl120">
            <a href="javascript:AjaxFormSubmit();" class="btn btn-primary j-add">保 存</a>
        </div>
    </form>
</div>

<script>

    window.onload=function (ev) {
        doConnect();
    }
    //建立连接
    function doConnect(){
        //alert('success');
        socket = new WebSocket('ws://localhost:13528');
        console.log(socket);
        // 打开Socket
        socket.onopen = function(event)
        {
            // 监听消息
            socket.onmessage = function(event)
            {
                var cmd=JSON.parse(event.data).cmd;
                switch (cmd){
                    case 'print':
                        alert('打印');
                        break;
                    case 'getPrinters':
                        var cmd=JSON.parse(event.data).printers;
                        var i;
                        var str='';
                        for(i in cmd){
                            str+='<label class="fi-name"><span class="colorRed"></span>打印机'+(i+1)+':'+cmd[i].name+'</label>';
                        }
                        $("#print_info").html(str)
                        break;
                    case 'setPrinterConfig':
                        alert('获取打印机配置');
                        break;
                    default:
                        alert(cmd);
                        break
                }
                console.log('Client received a message',event);
            };
            // 监听Socket的关闭
            socket.onclose = function(event)
            {
                console.log('Client notified socket has closed',event);
            };

        };
    }

    //获取打印机信息
    function doGetPrinters() {
        var request  = {
            requestID : '12345678901234567890',
            version : '1.0',
            cmd:'getPrinters'
        };

        socket.send(JSON.stringify(request));
    }

    //获取打印机配置
    function doPrinterConfig() {
        var request  = {
            requestID : "12345678901234567890",
            version : "1.0",
            cmd : "printerConfig"
        };
        socket.send(JSON.stringify(request));
    }

    function doSetPrinterConfig() {
        var request  = {
            requestID : "12345678901234567890",
            version : "1.0",
            cmd : "setPrinterConfig",
            printer : {
                name : "Canon G3000 series Printer",
                needTopLogo : true,
                needBottomLogo: false
            }
        };

        socket.send(JSON.stringify(request));
    }

    //打印
    function doPrint() {
        request  = {
            cmd : "print",
            requetID : "12345678901234567890",
            version : "1.0",
            task : {
                taskID : "1",
                preview : false,
                printer : "Canon G3000 series Printer",
                documents : [
                    {
                        documentID : "803571140776907261",
                        contents : [
                            //电子面单部分
                            {
                                "data":{
                                    "cpCode":"YTO",
                                    "needEncrypt":false,
                                    "parent":false,
                                    "recipient":{
                                        "address":{
                                            "city":"重庆市",
                                            "detail":"重庆市渝中区和泓江山国际7栋15-1",
                                            "district":"重庆市渝中区和泓江山国际7栋15-1",
                                            "province":"重庆",
                                            "town":"渝中区"
                                        },
                                        "mobile":"15523375429",
                                        "name":"刘洪",
                                        "phone":"057123222"
                                    },
                                    "routingInfo":{
                                        "consolidation":{
                                            "code":"230901"
                                        },
                                        "origin":{
                                            "code":"240050",
                                            "name":"辽宁省沈阳市新民市"
                                        },
                                        "routeCode":"800-011 028",
                                        "sortation":{
                                            "name":"800重庆"
                                        }
                                    },
                                    "sender":{
                                        "address":{
                                            "city":"沈阳市",
                                            "detail":"站前西路耐火材料厂对面",
                                            "district":"新民市",
                                            "province":"辽宁省"
                                        },
                                        "mobile":"17600058188",
                                        "name":"全民美妆第一平台",
                                        "phone":"17600058188"
                                    },
                                    "shippingOption":{
                                        "code":"STANDARD_EXPRESS",
                                        "title":"标准快递"
                                    },
                                    "waybillCode":"803571140776907261"
                                },
                                "signature":"MD:EuxOFuZu8YFnd2cza97WmQ==",
                                "templateURL":"http://cloudprint.cainiao.com/template/standard/301/176"
                            },
                            //自定义区部分
                            {
                                templateURL : "http://cloudprint.cainiao.com/cloudprint/customArea/queryCustomAreaList4Top.json?custom_area_id=642230",
                                data : {
                                    "item_name": "中科华标技术支持"
                                }
                            }
                        ]
                    }
                ]
            }
        };

        socket.send(JSON.stringify(request));
    }


</script>